const SERVICES_PROP = Symbol('services')
/**
 * 全局组件的状态管理
 */
export default {
  inject: {
    $services: SERVICES_PROP,
  },
  provide () {
    return (()=>{
			return this.$services?null:{
				[SERVICES_PROP]:  this.getServices ()
			}
		})()
  },
  methods: {
    /**
     * @returns {Object}
     * @protected
     */
    getServices () {
      return this.$services || {}
    },
  },
	/**
	 * 解决无注册属性时的报错
	 */
	beforeCreate () {
		let source = this.$parent
		while (source) {
			if (source._provided && SERVICES_PROP in source._provided) {
				break
			}
			source = source.$parent
		}
		if (!source || !(SERVICES_PROP in source._provided)) {
			delete this.$options.inject.$services
		}
	}
}
